package com.haozi.watchtomato.dto;

import org.springframework.http.HttpStatus;

import java.util.HashMap;

/**
 * @author haozi
 *
 */
public class HaoziResponse extends HashMap<String, Object>{
	private static final long serialVersionUID = -8713837118340960775L;

	public HaoziResponse success() {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(null);
		return this;
	}

	public HaoziResponse success(Object data) {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(data);
		return this;
	}

	public HaoziResponse success(Object data, String message) {
		this.code(HttpStatus.OK);
		this.message(message);
		this.data(data);
		return this;
	}

	public HaoziResponse fail() {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message("error");
		return this;
	}

	public HaoziResponse fail(String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message(message);
		return this;
	}

	public HaoziResponse fail(HttpStatus status, Object data, String message) {
		this.code(status);
		this.data(data);
		this.message(message);
		return this;
	}

	public HaoziResponse fail(Object data, String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(data);
		this.message(message);
		return this;
	}

	public HaoziResponse code(HttpStatus status) {
		this.put("code", status.value());
		return this;
	}

	public HaoziResponse message(String message) {
		this.put("message", message);
		return this;
	}

	public HaoziResponse data(Object data) {
		this.put("data", data);
		return this;
	}

	@Override
	public HaoziResponse put(String key, Object value) {
		super.put(key, value);
		return this;
	}

}
